﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using quanlynhasach.Linksql;

namespace quanlynhasach
{
    public partial class frmTimNCC : Form
    {
        Connection db = new Connection();
        public frmTimNCC()
        {
            InitializeComponent();
        }

        private void frmTimNCC_Load(object sender, EventArgs e)
        {
            Dock = DockStyle.Fill;
            dataGridView1.DefaultCellStyle.ForeColor = Color.Blue;
            dataGridView1.DataSource = db.getDS("Select * from NhaCungCap where MaNhaCungCap <> 'N/A'");
            rb1.Checked = true;
            dataGridView1.AllowUserToAddRows = false;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            DataTable NCC = new DataTable();
            if (rb2.Checked)
                NCC = db.getDS("Select * from NhaCungCap Where MaNhaCungCap LIKE '%" + textBox1.Text + "%' and MaNhaCungCap <> 'N/A'");
            if (rb3.Checked)
                NCC = db.getDS("Select * from NhaCungCap Where TenNCC LIKE '%" + textBox1.Text + "%' and MaNhaCungCap <> 'N/A'");
            if (rb4.Checked)
                NCC = db.getDS("Select * from NhaCungCap Where DiaChi LIKE '%" + textBox1.Text + "%' and MaNhaCungCap <> 'N/A'");
            if (rb5.Checked)
                NCC = db.getDS("Select * from NhaCungCap Where MaSoThue LIKE '%" + textBox1.Text + "%' and MaNhaCungCap <> 'N/A'");
            if (rb1.Checked)
                NCC = db.getDS("Select * from NhaCungCap Where (MaNhaCungCap LIKE '%" + textBox1.Text + "%' or TenNCC LIKE '%" + textBox1.Text + "%' or DiaChi LIKE '%" + textBox1.Text + "%' or MaSoThue LIKE '%" + textBox1.Text + "%') and MaNhaCungCap <> 'N/A'");
            dataGridView1.DataSource = NCC;
        }
    }
}
